package daphne.noterun.notes 
{
	import daphne.noterun.objects.GameObject;
	import daphne.noterun.objects.Note;
	import daphne.noterun.menus.Main;
	import daphne.noterun.menus.Room;
	import daphne.noterun.objects.Coin;
	 
	/**
	 * ...
	 * @author Daphne
	 */
	public class CoinContainer extends GameObject
	{
		public var coins:Array;
		
		public function CoinContainer(room:Room) 
		{
			super(room)
			this.coins = new Array();
		}
		
		public function addCoinOverNote(note:Note)
		{
			var coin:Coin = new Coin(this.room);
			this.coins.push(coin);
			this.room.addChild(coin);
			
			coin.x = note.x + (note.width / 2);
			coin.y = note.y - coin.height;
		}
		
		public override function update():void
		{
			var numNotesOffStage:int = 0;
			
			var coin:Coin;
			for each (coin in this.coins)
			{
				coin.update();
				if (coin.x > Main.STAGE_WIDTH)
				{
					numNotesOffStage++;
					this.room.removeChild(coin);
				}
				
				if (coin.getBounds(this.room).intersects(this.room.player.getBounds(this.room)))
				{
					coin.visible = false;
				}
			}
			
			
			//get rid of all the notes that are off the stage
			this.coins.splice(0, numNotesOffStage);
		}
	}

}